<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta http-equiv="cache-control" content="no-cache" />
		<meta http-equiv="expires" content="0" />
		<meta name="viewport"
			content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes" />
		<meta name="apple-mobile-web-app-status-bar-style" content="white" />
		<meta name="format-detection" content="telephone=no" />
		<!--Iphpone电话号码串识别 -->
		<meta http-equiv="x-rim-auto-match" content="none" />
		<!--电话号码串识别 -->
		<title>拨云见日科技</title>
		<link rel="SHORTCUT ICON" href="/static/favicon.ico" type="image/x-icon"/>
		<script src='/static/js/jquery.js' type='text/javascript'></script>
		<script src='/static/js/qrcode.js' type='text/javascript'></script>
		<script src='/static/js/layui.js' type='text/javascript'></script>
		<link href="/static/css/index.css" rel="stylesheet" type="text/css" />
		<link href="/static/css/layui.css" rel="stylesheet" type="text/css" />
	</head>
	<body>
    <div class="header">
        <!--工号信息-->
<!--        <div class="user">-->
<!--            <div style="text-align:center;font-size: 30px;">拨云见日智能操作平台</div>-->
<!--        </div>-->
        {% include "base.html" %}
    </div>
		<div class="wrapper">
			<!--功能二维码-->
            <div class="wrapper_cont">
				<div class="duty"></div>
			</div>
			{% include "right.html" %}
			<div class="layui-panel" style="padding: 10pt;width: 85%;">
                <form class="layui-form" action="">
                    <div class="layui-form-item">
                      <label class="layui-form-label">产品码</label>
                      <div class="layui-input-block">
                        <input type="text" id="pcode" autofocus="autofocus"  lay-verify="required" autocomplete="off" class="layui-input">
                      </div>
                    </div>
					<div class="layui-form-item">
                      <label class="layui-form-label">产品名称</label>
                      <div class="layui-input-block">
                        <span id="pname"></span>
                      </div>
                    </div>
					<div class="layui-form-item">
                      <label class="layui-form-label">数量</label>
                      <div class="layui-input-block">
                        <input type="text" id="pnum" autofocus="autofocus"  lay-verify="required" autocomplete="off" class="layui-input">
                      </div>
                    </div>
                    <div class="layui-form-item">
                      <label class="layui-form-label">容器码</label>
                      <div class="layui-input-block">
                        <input type="text" id="ccode" autofocus="autofocus"  required="" lay-verify="required" autocomplete="off" class="layui-input">
                      </div>
                    </div>
                  </form>
              </div>
			</div>
		</div>
	</body>
	<script type='text/javascript'>
		var param = "{{data}}"
		$(function(){
			getValue();
		})

        function getValue(){
		    v = document.getElementById('v').value;
		    if(commFun(v)){
		    	return;
			}
            var isFoucs = true;
            $(".layui-input").each(function(e,item){
                var v = $(item).val();
                if(commFun(v,param)){
		    		return;
				}
                if(!v&&isFoucs){
                    $(item).focus();
                    isFoucs = false;
                }
                id = $(item).attr("id");
                html = $("#pname").html();
                if(id=='pcode'&&v.length>0&&html.length==0){
                	searcData(v)
				}
            });
            if(isFoucs){
                $("#v").focus();
            }
            setTimeout(getValue,1000);
        }

        function searcData(v) {
			var action = $("#mm").attr("action")
			var sql = "select pt.name from product_product pp inner join product_template pt on pp.product_tmpl_id = pt.id \n" +
					"where pp.barcode='"+v+"'";
			$.post(action, {sql: sql}, function (result) {
				result = JSON.parse(result);
				if(result.length==0){
					$("#pname").html("<em style='color:red'>产品不存在</em>");
				}else{
					var rs = result[0][0];
					$("#pname").html(rs);
				}
			})
		}
		function submit() {
			var barcode = $("#pcode").val();
			var pnum = $("#pnum").val();
			var ccode = $("#ccode").val();
			var action = $("#mm").attr("action")
			var sql = "update byjr_container set product_code='"+barcode+"',product_qty="+pnum+"" +
					",product_weight=0,product_batch='',shelve_code='' where container_code='"+ccode+"'";
			$.post(action, {sql: sql}, function (result) {
				layer.msg("绑定成功");
				setTimeout(function(){
					var robot_id = '{{data}}';
					location.href = "index.html?data="+robot_id
				},1000);
			})
		}
	</script>
	{% include "footer.html" %}
</html>
